<template>
     <van-button :icon="value? 'star':'star-o'"
      :class="value? 'yellow':'nomal'"
     :loading="loading"
     @click="onCollect"
     />
       <!-- <van-icon
          color="#777"
          :name="value?'star-o':'star'"
        /> -->
</template>

<script>
import { addCollect, deleteCollect } from '@/api/article'
export default {
  name: 'CollectArticle',
  components: {},
  props: {
    value: {
      type: Boolean,
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  data () {
    return {
      loading: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    async  onCollect () {
      this.loading = true
      try {
        if (this.value) {
          await deleteCollect(this.articleId)
        } else {
          await addCollect(this.articleId)
        }
        this.$emit('input', !this.value)
        this.$toast.success(!this.value ? '收藏成功' : '取消收藏')
      } catch (err) {
      //  window.console.log(err)
        let message = '操作失败，请重试！'
        if (err.response && err.response.status === 401) {
          message = '用户未登录，请先登录！'
        }
        this.$toast.fail(message)
      }
      this.loading = false
    }

  }
}
</script>

<style scoped lang="less">
.yellow{
    .van-icon {
    color: #ffa500;

}
}
.normal{
    .van-icon{
        color: #777;
    }
}

</style>
